'''
This file is part of Lampy.

Lampy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Lampy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Lampy.  If not, see <http://www.gnu.org/licenses/>.

Copyright 2011 Kevin Han
'''

"""Globals and small utilities used throughout."""
import hashlib

FUNC_CHAR = '/'

def isFunc(node):
    """Return True if node is a function."""
    return node[0][0] == FUNC_CHAR and node[0] != FUNC_CHAR

def isCompound(node):
    """Return True if node is a compound expression (not a function or name)."""
    return not isName(node) and not isFunc(node)

def isName(node):
    """Return True if node is a name."""
    return isinstance(node, basestring) and len(node) == 1 and node != FUNC_CHAR

def splitFunc(func):
    """Return (params, body)."""
    return func[0][1:], func[1]

def makeFunc(params, body):
    """Return a function from list of names (params) and body node."""
    return [FUNC_CHAR + params, body]
